#include <stdio.h>
#include <string.h>
int n;
char s1[5005];
char s2[5005];
short dp[5005][5005];

int main()
{
    int i, j;
    while(1)
    {
            if(scanf("%d", &n) == EOF) break;
            scanf("%s", s1+1);
    
            for(i = 1; i <= n; i++)
            {
                s2[n - i +1] = s1[i];
            }
            memset(dp,0,sizeof(dp));
            
            if(s1[1] == s2[1])
                     dp[1][1] = 1;
            else dp[1][1] = 0;
            
            for(i = 2; i <= n; i++)
            {
                  if(s2[1] == s1[i])  dp[i][1] = 1;
                  else dp[i][1] = dp[i - 1][1];
            }
            for(i = 2; i <=n; i++)
            {
                  if(s1[1] == s2[i])  dp[1][i] = 1;
                  else dp[1][i] = dp[1][i - 1];
            }
            
            for(i = 2; i <= n; i++)
                for(j = 2; j <= n; j++)
                {
                      if(s1[i] == s2[j])
                               dp[i][j] = dp[i - 1][j - 1] + 1;
                      else 
                      {                     
                              dp[i][j] = dp[i - 1][j - 1];
                              if(dp[i][j - 1] > dp[i][j]) 
                                      dp[i][j] = dp[i][j - 1];
                              if(dp[i - 1][j] > dp[i][j])
                                      dp[i][j] = dp[i - 1][j];
                      }
                }
                
            printf("%d\n", n - dp[n][n]);
    }
    return 0;
             
    
}
